/*     */ package cc.s2m.web.s2mBlog.interceptors;
/*     */ 
/*     */ import cc.s2m.util.CookieUtil;
/*     */ import cc.s2m.web.s2mBlog.pojo.Admin;
/*     */ import cc.s2m.web.s2mBlog.pojo.AdminActions;
/*     */ import cc.s2m.web.s2mBlog.pojo.AdminRoleActions;
/*     */ import cc.s2m.web.s2mBlog.pojo.AdminRoles;
/*     */ import cc.s2m.web.s2mBlog.service.IAdminActions;
/*     */ import cc.s2m.web.s2mBlog.service.IAdminRoleActions;
/*     */ import cc.s2m.web.s2mBlog.service.IAdminRoles;
/*     */ import cc.s2m.web.s2mBlog.util.MemcacheKeys;
/*     */ import cc.s2m.web.s2mBlog.util.StaticProp;
/*     */ import com.google.common.base.Strings;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.List;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.spy.memcached.MemcachedClient;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/*     */ 
/*     */ public class AdminInterceptor extends HandlerInterceptorAdapter
/*     */ {
/*     */ 
/*     */   @Autowired
/*     */   private MemcachedClient memcachedClient;
/*     */ 
/*     */   @Autowired
/*     */   private IAdminActions adminActionsService;
/*     */ 
/*     */   @Autowired
/*     */   private IAdminRoleActions adminRoleActionsService;
/*     */ 
/*     */   @Autowired
/*     */   private IAdminRoles adminRolesService;
/*     */ 
/*     */   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
/*     */     throws Exception
/*     */   {
/*  46 */     String adminLoginUrl = "/admin/login";
/*  47 */     CookieUtil cookie = new CookieUtil(request, response);
/*  48 */     String cookieId = cookie.getCookie(StaticProp.cookieID);
/*  49 */     if ((cookieId == null) || (cookieId.trim().isEmpty())) {
/*  50 */       response.sendRedirect(adminLoginUrl);
/*  51 */       return false;
/*     */     }
/*  53 */     Admin admin = (Admin)this.memcachedClient.get(MemcacheKeys.ADMIN_SESSION.getKey() + cookieId);
/*  54 */     if (admin == null) {
/*  55 */       response.sendRedirect(adminLoginUrl);
/*  56 */       return false;
/*     */     }
/*     */ 
/*  63 */     String uri = request.getRequestURI();
/*  64 */     if ((!Strings.isNullOrEmpty(uri)) && (uri.endsWith("/"))) {
/*  65 */       uri = uri.substring(0, uri.length() - 1);
/*     */     }
/*  67 */     AdminActions actions = new AdminActions();
/*  68 */     actions.setUrl(uri);
/*  69 */     actions = (AdminActions)this.adminActionsService.getByCondition(actions);
/*  70 */     if (actions == null) {
/*  71 */       actions = new AdminActions();
/*  72 */       actions.setUrl(uri);
/*  73 */       this.adminActionsService.insertSelective(actions);
/*     */     }
/*     */ 
/*  76 */     if (!admin.getUsername().equals("admin")) {
/*  77 */       AdminRoleActions roleActions = new AdminRoleActions();
/*  78 */       roleActions.setAid(actions.getId());
/*  79 */       List<AdminRoleActions> roleActionsList = this.adminRoleActionsService.getList(roleActions, null);
/*  80 */       if (roleActionsList.isEmpty()) {
/*  81 */         response.setCharacterEncoding("UTF-8");
/*  82 */         response.setContentType("text/plain; charset=UTF-8");
/*  83 */         response.getWriter().println("您无权进行该操作！");
/*  84 */         return false;
/*     */       }
/*  86 */       boolean pass = false;
/*  87 */       for (AdminRoleActions roleActions_ : roleActionsList) {
/*  88 */         AdminRoles adminRole = new AdminRoles();
/*  89 */         adminRole.setAid(admin.getId());
/*  90 */         adminRole.setRid(roleActions_.getRid());
/*  91 */         adminRole = (AdminRoles)this.adminRolesService.getByCondition(adminRole);
/*  92 */         if (adminRole != null) {
/*  93 */           pass = true;
/*  94 */           break;
/*     */         }
/*     */       }
/*  97 */       if (!pass) {
/*  98 */         response.setCharacterEncoding("UTF-8");
/*  99 */         response.setContentType("text/plain; charset=UTF-8");
/* 100 */         response.getWriter().println("您无权进行该操作！");
/* 101 */         return false;
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 106 */     this.memcachedClient.replace(MemcacheKeys.ADMIN_SESSION.getKey() + cookieId, 1800, admin);
/* 107 */     request.setAttribute("sessionAdmin", admin);
/* 108 */     return true;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.interceptors.AdminInterceptor
 * JD-Core Version:    0.6.1
 */